<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
	<head> 
    <meta charset="UTF-8">
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css"> 
    <link href="${ctxStatic}/layout/css/main.css" rel="stylesheet" type="text/css" />
	<link href="${ctxStatic}/layout/css/jquery-fallr-1.3.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="${ctxStatic}/layout/js/jquery-1.7.1.min.js"></script>
	<script type="text/javascript" src="${ctxStatic}/layout/js/ui/ui.core.min.js"></script>
	<script type="text/javascript" src="${ctxStatic}/layout/js/ui/ui.sortable.min.js"></script>
	<script type="text/javascript" src="${ctxStatic}/layout/js/jquery-fallr-1.3.pack.js"></script>
	<script type="text/javascript" src="${ctxStatic}/layout/js/jquery.easing.1.3.js"></script>
	<script type="text/javascript" src="${ctxStatic}/layout/js/Jh.js"></script>
    <script type="text/javascript">

    $(document).ready(function () {	

    	var DATA = {

    		'appL' : {
				<c:forEach items="${leftList}" var="temp">
    				"${temp.systemId}-${temp.itemFlag}":"${temp.itemValue}"+" / "+"${temp.itemNameCn}",
    			</c:forEach>
    		},

    		'appR' : {

    			<c:forEach items="${rightList}" var="temp">
    				"${temp.systemId}-${temp.itemFlag}":"${temp.itemValue}"+" / "+"${temp.itemNameCn}",
				</c:forEach>

    		}

    	}	
		
    	Jh.fn.init(DATA);

    	Jh.Portal.init(DATA);

    });
    
    /*  */
    function saveSort(){
    	var leftPart_Length = $("#portal_l > .groupItem").length;
    	var rightPart_Length = $("#portal_r > .groupItem").length;
    	/**
    	 * 如果 该工序无项目， 不得保存  
    	 */
    	if ($("#portal_l > .groupItem") == "undefined" || leftPart_Length == 0) {
			alertInfo("当前工序无项目，无法保存！");
			return;
		}
    	/**
    	 * 左侧项目数量只能比右侧多一个或相等 !——————————————————	   或	——————————————————
    	 * 							  | ——————  —————— |	| ——————  —————— |
    	 *							  | ——————  —————— |	| ——————  —————— |
    	 *							  | ——————  —————— |	| ——————  —————— |
    	 *							  | ——————  	   |	|				 |
    	 *							  ——————————————————	——————————————————
    	 */
    	if (leftPart_Length < rightPart_Length || leftPart_Length - rightPart_Length > 1) {
    		alertInfo("左侧项目数量只能比右侧多一个或相等！");
    		return;
		}
    	var html = "";
    	/**
    	 * 设置左侧部分项目数据，集合下标和排序sort按照 奇数 设置 
    	 */
    	$("#portal_l > .groupItem").each(function(i,e){
    		var idStr = $(this).attr("id");
    		html += "<input type='hidden' name='operatingRList["+2*i+"].systemId' value='"+idStr.split("-")[0]+"'>";
    		html += "<input type='hidden' name='operatingRList["+2*i+"].itemFlag' value='"+idStr.split("-")[1]+"'>";
    		html += "<input type='hidden' name='operatingRList["+2*i+"].sort' value='"+(2*i+1)+"'>";
    		$("#inputForm").append(html);
    		html = "";
    	})
    	/**
    	 * 设置右侧部分项目数据，集合下标和排序sort按照 偶数 设置 
    	 */
    	$("#portal_r > .groupItem").each(function(i,e){
    		var idStr = $(this).attr("id");
    		html += "<input type='hidden' name='operatingRList["+(2*i+1)+"].systemId' value='"+idStr.split("-")[0]+"'>";
    		html += "<input type='hidden' name='operatingRList["+(2*i+1)+"].itemFlag' value='"+idStr.split("-")[1]+"'>";
    		html += "<input type='hidden' name='operatingRList["+(2*i+1)+"].sort' value='"+(2*i+2)+"'>";
    		$("#inputForm").append(html);
    		html = "";
    	})
    	//$("#activity_pane").showLoading();
       	var params = $("#inputForm").serialize();
       	$.post("${ctx}/check/project/saveSort",params,function(result){
       		//$("#activity_pane").hideLoading();
       		if (result == "true") {
	       		tipParent("Success");
	       		closeWin();
			}else {
				tipParent("Failed");
			}
       	});
    }

    </script>
    </head>
	<body id="activity_pane">
	<div id="editPage" class="layerHeader clearfix">
        <!--编辑-->
        <p class="headerTitle">设置<%="【 "%>${operatingName }<%=" 】"%>工序画面布局</p>
	    <div class="headerButton clearfix">
	    	<button type="button" onclick="saveSort()"><spring:message code="common_save"/></button>
	        <button type="button" onclick="closeWin()"><spring:message code="btn_cancle"/></button>
	    </div>
	</div>
	<form id="inputForm" method="post">
	</form>
	</body>
</html>